package com.jsmile.cloud.tradecenter.api.res;

import java.util.List;
import java.util.Objects;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel
public class ResOrderList {

    @ApiModelProperty(value = "订单编号")
    private List<ResOrder> orders;
    @ApiModelProperty(value = "活动id")
    private Long activityId;
    @ApiModelProperty(value = "付款方式，1-余额支付  2微信支付  3支付宝支付")
    private Integer payMethod;
    @ApiModelProperty(value = "租户id")
    private Long tenantId;

    @ApiModelProperty(value = "是否走支付通道：true是 false余额支付")
    private Boolean hasPay = true;

    // 商品总金额
    public Long getProductAmountTotal() {
        return this.getOrders().stream().mapToLong(order -> {
            return order.getOrderProducts().stream().mapToLong(ResOrderProduct::getProductAmount).sum();
        }).sum();
    }

    // 商品总数量
    public Long getProductNumber() {
        return this.getOrders().stream().mapToLong(order -> {
            return order.getOrderProducts().stream().mapToLong(ResOrderProduct::getProductNumber).sum();
        }).sum();
    }

    // 商品应该付款总金额
    public Long getActuallyPayAmount() {
        return this.getOrders().stream().filter(Objects::nonNull).mapToLong(ResOrder::getActuallyPayAmount).sum();
    }

    // 商品余额付款总金额
    public Long getBalanceAmount() {
        return this.getOrders().stream().filter(Objects::nonNull).mapToLong(ResOrder::getBalanceAmount).sum();
    }

    // 商品优惠券总金额
    public Long getTicketDisamt() {
        return this.getOrders().stream().filter(Objects::nonNull).mapToLong(ResOrder::getTicketDisamt).sum();
    }

    // 商品积分付款总金额
    public Long getPointDisamt() {
        return this.getOrders().stream().filter(Objects::nonNull).mapToLong(ResOrder::getPointDisamt).sum();
    }
}
